import { Component, ViewChild, ElementRef, HostListener, ViewChildren } from '@angular/core';
import { filter } from 'rxjs/operators'
import { NavigationEnd, Router } from '@angular/router';
declare let $

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.less']
})
export class AppComponent {
  title = 'web-app';
  @ViewChild('bodyEle', { static: true }) bodyEle: ElementRef;
  height;
  isPadding = false;
  @HostListener('window:resize', ['$event'])
  onResize(event) {
    // console.log(event.target.innerWidth);
    this.setIsPadding()
  }
  isShow = location.pathname != "/" && history.state && history.state.navigationId > 1
  constructor(private route: Router) {

  }
  ngOnInit(): void {
    //Called after the constructor, initializing input properties, and the first call to ngOnChanges.
    //Add 'implements OnInit' to the class.
    this.route.events.pipe(
      filter(event => event instanceof NavigationEnd)
    ).subscribe((event: NavigationEnd) => {
      this.isShow = location.pathname != "/" && history.state && history.state.navigationId > 1

      setTimeout(()=>{
        this.setIsPadding()
      },300)
    });

    // console.log(this.bodyEle)
  }

  ngAfterContentInit(){
    this.setIsPadding()
  }

  setIsPadding() {
      this.isPadding = this.bodyEle.nativeElement.nextElementSibling.firstChild.clientHeight + 120> $(window).outerHeight()
      // console.log(this.bodyEle.nativeElement.nextElementSibling.firstChild.clientHeight)
  }
  back() {
    history.go(-1);
  }
}
